package com.vancouver.knows.ui.fragment.event;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import com.pangu.task.IResultReceiver;
import com.pangu.task.mark.ATaskMark;
import com.pangu.ui.refresh.ARefreshViewController;
import com.pangu.ui.refresh.RefreshControllerView;
import com.vancouver.knows.MainApplication;
import com.vancouver.knows.R;
import com.vancouver.knows.ui.view.PullScrollView;
import com.vancouver.knows.business.bean.UserInfo;

/**
 * 活动详情下拉界面
 * 
 * @author chenxunlin01
 * 
 */
public class EventPullDetailControllerView extends RefreshControllerView {

	private ATaskMark aTaskMark;
	private String postId;
	private IResultReceiver resultReceiver;

	public EventPullDetailControllerView(Context context) {
		super(context);
	}

	public EventPullDetailControllerView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public void init(String postId, ATaskMark aTaskMark, IResultReceiver resultReceiver) {
		this.postId = postId;
		this.aTaskMark = aTaskMark;
		this.resultReceiver = resultReceiver;
		((PullScrollView) content).init(aTaskMark);
	}

	@Override
	public void onRefresh(ARefreshViewController controller) {
		if (aTaskMark != null && aTaskMark.getTaskStatus() != ATaskMark.HANDLE_DOING) {
			aTaskMark.reinitTaskMark();
			aTaskMark.setTaskType(ATaskMark.TYPE_REFRESH);
			loadData();
		}
	}

	public void loadData() {
		UserInfo userInfo = ((MainApplication) imContext).getBusinessModule().getCacheManager().getUserInfo();
		String userId = userInfo == null ? "" : userInfo.getUserID();
		((MainApplication) imContext).getBusinessModule().getServiceWrapper()
				.fetchEventDetail(resultReceiver, aTaskMark, postId, userId);
	}

	@Override
	protected View createContentView() {
		PullScrollView scrollView = (PullScrollView) LayoutInflater.from(getContext()).inflate(
				R.layout.view_event_detail_main_content, null);
		return scrollView;
	}

}
